package zuo.algo.c06;

import zuo.algo.data.TreeNode;
import zuo.algo.util.TreeUtils;

/**
 * 00:52-二叉树递归遍历
 */
public class TreeTraversal1 {

    public static void recursive(TreeNode root) {
        recursiveFirst(root);
        System.out.println();
        recursiveInfix(root);
        System.out.println();
        recursiveAfter(root);
        System.out.println();
    }

    private static void recursiveFirst(TreeNode node) {
        if (node == null) {
            return;
        }
        System.out.print(node.val + " ");
        recursiveFirst(node.left);
        recursiveFirst(node.right);
    }

    private static void recursiveInfix(TreeNode node) {
        if (node == null) {
            return;
        }
        recursiveInfix(node.left);
        System.out.print(node.val + " ");
        recursiveInfix(node.right);
    }

    private static void recursiveAfter(TreeNode node) {
        if (node == null) {
            return;
        }
        recursiveAfter(node.left);
        recursiveAfter(node.right);
        System.out.print(node.val + " ");
    }

    public static void main(String[] args) {
        TreeNode root = TreeUtils.getTree();
        recursive(root);
    }
}
